from tools.driver import open_dingstock
from unittest import TestCase
from pages.recommend_page import RecommendPage
from pages.mine_page import MinePage
from pages.newest_page import NewestPage
import unittest
from time import sleep


class TestComment(TestCase):
    def setUp(self) -> None:
        self.driver = open_dingstock()
        self.recommendpage = RecommendPage(self.driver)
        self.minepage = MinePage(self.driver)
        self.newestpage = NewestPage(self.driver)

    def tearDown(self) -> None:
        sleep(1)

    def test_a_comment_trend_1(self):
        """测试动态一级评论"""
        comment_text = '测试动态一级评论'
        look_image_resourceId = 'cool.dingstock.mobile:id/circle_view_dynamic_subcomment_better_link_txt'
        self.recommendpage.switch_newest()
        self.newestpage.into_second_trend()
        origin_num = self.newestpage.get_comment_num()
        self.newestpage.input_comment(comment_text)
        self.newestpage.click_send_comment()
        new_num = self.newestpage.get_detail_comment_num()
        assert origin_num != new_num and self.newestpage.is_resource_id_exist(look_image_resourceId)

    @unittest.skip('评论🚫：5分钟内不能再次发送，跳过用例')
    def test_b_comment_trend_2(self):
        """测试动态二级评论"""
        level2_comment_text = '动态二级评论2'
        look_image_resourceId = 'cool.dingstock.mobile:id/circle_view_dynamic_subcomment_better_link_txt'
        self.recommendpage.switch_newest()
        self.newestpage.into_second_trend()
        origin_num = int(self.newestpage.get_comment_num())
        self.newestpage.send_level2_comment(level2_comment_text)
        new_num = int(self.newestpage.get_comment_num())
        assert new_num-1 == origin_num and self.newestpage.is_resource_id_exist(look_image_resourceId)

    def test_c_comment_like_1(self):
        """测试点赞动态一级评论和取消点赞"""
        self.recommendpage.switch_newest()
        self.newestpage.into_second_trend()
        sleep(1)
        self.newestpage.like_level1_comment()
        like = self.newestpage.is_like_num_exist()
        sleep(1)
        self.newestpage.cancel_like_level1_comment()
        cancel_like = self.newestpage.is_like_num_exist()
        assert like == True and cancel_like == False

    def test_d_delete_comment(self):
        """测试删除动态一级评论"""
        self.recommendpage.switch_newest()
        self.newestpage.into_second_trend()
        origin_num = int(self.newestpage.get_comment_num())
        self.newestpage.delete_first_comment()
        new_num = int(self.newestpage.get_comment_num())
        assert new_num != origin_num

    def test_e_copy_comment(self):
        """测试复制动态一级评论"""
        self.recommendpage.switch_newest()
        self.newestpage.into_second_trend()
        self.newestpage.copy_first_comment()
        assert self.newestpage.is_text_toast_exist('已复制')

    def test_f_report_comment(self):
        """测试举报动态一级评论"""
        self.recommendpage.switch_newest()
        self.newestpage.into_second_trend()
        self.newestpage.report_first_comment()
        assert self.newestpage.is_text_toast_exist('举报成功')


if __name__ == '__main__':
    unittest.main()